package com.ynnz.test;

import com.ynnz.pojo.Customer;
import com.ynnz.service.CustomerService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @Title: test
 * @Description:
 * @PACKAGE_NAME：com.ynnz
 * @Author: 94358 fangjinsen
 * CreateDate: 2022/5/9 9:15
 */
public class test {
    private ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
    private CustomerService customerService = context.getBean(CustomerService.class);

    @Test
    public void insertCustomer() {
        List<Customer> customers = customerService.queryCustomer();
        if (customers.size() == 0) {
            Customer customer = new Customer(1, "新增测试数据1", 1, 1, "1", "1", "1", "1", "1", "2022-1-23 12:12:12");
            int i = customerService.insertCustomer(customer);
            if (i > 0) {
                System.out.println("新增测试数据成功");
                customers = customerService.queryCustomer();
                System.out.println("新增测试数据为：" + customers);
            }
        }
    }


    @Test
    public void updateCustomer() {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu/MM/dd HH:mm:ss");
        LocalDateTime now = LocalDateTime.now();
        System.out.println(dtf.format(now));                  //  2021/03/22 16:37:15
        Customer customer = new Customer(1, "更改后的数据", 1, 1, "1", "1", "1", "1", "1", "2022-1-23 12:12:12");
        int i = customerService.updateCustomer(customer);
        if (i > 0) {
            System.out.println("更新测试数据成功");
            List<Customer> customers = customerService.queryCustomer();
            System.out.println("更新后数据为：" + customers);
        }
    }

    @Test
    public void deleteCustomer() {
        int i = customerService.deleteCustomer(1);
        if (i > 0) {
            System.out.println("删除测试数据成功");
        }
    }
}
